package com.yun.zf.system.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class RedissonConfig {
    @Value("${spring.profiles.active}")
    private String active;


    @Bean
    public RedissonClient redisson() throws IOException {

        // 两种读取方式，Config.fromYAML 和 Config.fromJSON
//        Config config = Config.fromJSON(RedissonConfig.class.getClassLoader().getResource("redisson.json"));
        String yml ="";
        if (active.equals("pro")){
            yml ="redisson-pro.yml";
        }else {
            yml="redisson-dev.yml";
        }
        Config config = Config.fromYAML(RedissonConfig.class.getClassLoader().getResource(yml));
        return Redisson.create(config);
    }
}
